package mi.payment.transaction;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ScrollView;

/**
 * @author Created by longx on 2017/7/19.
 */
public class MenuScrollview extends ScrollView {

    private ScrollBottomListener listener;

    public MenuScrollview(Context context) {
        super(context);
    }

    public MenuScrollview(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MenuScrollview(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onScrollChanged(int l, int t, int oldL, int oldT) {
        super.onScrollChanged(l, t, oldL, oldT);
        if (t + getHeight() >= computeVerticalScrollRange()) {
            listener.onBottom();
        }
        if (t + getHeight() < computeVerticalScrollRange()) {
            listener.down();
        }
        if (t == 0) {
            listener.onTop();
        }
    }

    public void setOnScrollBottom(ScrollBottomListener listener) {
        this.listener = listener;
    }

    public interface ScrollBottomListener {

        void onBottom();

        void onTop();

        void down();

    }


}
